< previous page page_227 next page >

Page 227
0227-01.jpg
Figure 11.3
Although typing a procedure by hand
is faster, you can also create a new
procedure in the current module or form
by using the Add Procedure dialog box.
In the Add Procedure dialog box, perform the following steps to create the shell of your procedure:
1. Enter the name of the procedure in the Name text box.
2. Choose the type of procedure (Sub, Function, Property, or Event).
3. Choose the scope of the procedure (Public or Private).
4. Check the All Local Variables as Statics check box if necessary.
To create a procedure, you need to choose the sub procedure type. You are presented with four choices. A function type of procedure returns a specific value. These procedures are covered later in this chapter. A property procedure sets or retrieves the value of a property in a form or class module. An event procedure responds to an event in a form or class module; choosing Event in this dialog box inserts a forward declaration to a user-defined event that you will create. The Property and Event procedures are described in Chapter 16, "Classes: Reusable Components."
sarrow.gifSee "Property Procedures," p. 359
After you enter the necessary information, click OK. Visual Basic then creates the framework of a procedure in the Code window.
Running the Procedure
After you develop a procedure, you need a way to run it from other parts of your program. You can choose from two methods for running a procedure: use the Call statement or use just the procedure name. With either method, you simply specify the procedure name and any arguments that are required by the procedure. (The arguments are the ones specified in the Sub statement when you defined the procedure.)
The syntax for running a procedure is as follows:
Call procname([arguments])
or
procname arguments
In either syntax, procname refers to the name of the procedure. This name is specified in the Sub statement that defined the procedure. Arguments refers to the parameters passed to the procedure. In the calling statement, the arguments can be literal values, variables, or functions that return the proper data type. This is different from the Sub statement in which all the arguments have to be variable names. Parameters, if present, must be separated by commas.

 
< previous page page_227 next page >